package com.lw.udpchat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;

/**
 * @author LW
 * @2020/9/16 10:48
 */
public class UDPSenderDemo01 {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(8888);

        while (true){
            //准备数据：控制台读取System.in
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

            String data = reader.readLine();//读取这一行
            byte[] datas = data.getBytes();
            DatagramPacket packet = new DatagramPacket(datas,0,datas.length,new InetSocketAddress("localhost",6666));

            socket.send(packet);
            if(data.equals("bye")){
                break;
            }
        }


        socket.close();

    }
}
